<?php
include_once 'module/controls.php';
include_once 'js/ckeditor/ckeditor.php';
$c = new controls();
?>
<div id="content">
    <div class="content_block">
        <h2 class="jquery_tab_title"><?php echo $phrase["manager_banner"] ?></h2>
        <form method="post" action="<?= $url["home"] ?>/menu/banner-process" enctype="multipart/form-data">
            <p>
                <?php echo $c->get_label($phrase["banner_url"]) ?>
                <?php echo $c->get_textReadOnly("bannerurl") ?>
                <input class="button" type="button" value="Browser" onclick="BrowseServer();" />
                <span id="errorUrl" style="display: none">Url không được để trống.</span>
            </p>
            
            <p>
                <?php echo $c->get_label($phrase["lienket_link"]) ?>
                <?php echo $c->get_text("banner_link") ?>
                <span id="errorLink" style="display: none">Link không được để trống hoặc Định dạng Link sai.</span>
            </p>
            
            <p>
                <?php echo $c->get_label($phrase["banner_position"]) ?>
                <select name="banner_position" id="banner_position" >
                    <option value="0"><?= $phrase["banner_top"] ?></option>
                    <option value="1"><?= $phrase["banner_right"] ?></option>
                </select>
            </p>

            <p>
                <?php echo $c->get_label($phrase["banner_display"]) ?>
                <select name="banner_display" id="banner_display" >
                    <option value="0"><?= $phrase["no"] ?></option>
                    <option value="1"><?= $phrase["yes"] ?></option>
                </select>
            </p>
            <p>
                <?php echo $c->get_button("accept", $phrase["accept"]) ?>
            </p>
            <p><img id="images"/></p>
        </form>
    </div>
</div>
<script type="text/javascript">    
    function BrowseServer()
    {
        // You can use the "CKFinder" class to render CKFinder in a page:
        var finder = new CKFinder();
        finder.basePath = "<?= $url["home"] ?>/js/ckfinder/";	// The path for the installation of CKFinder (default = "/ckfinder/").
        finder.selectActionFunction = SetFileField;
        finder.popup();
    }

    // This is a sample function which is called when a file is selected in CKFinder.
    function SetFileField( fileUrl )
    {
        $("#images").attr("src", fileUrl);
        $('#bannerurl').val(fileUrl);
    }
    
    $('#accept').click(function(){
        var linkReg = /^([\w-\.]+([\w-]+\.)+[\w-]{2,4})?$/;
        var link = $('#banner_link').val();
        var url = $('#bannerurl').val();
        if(url == ""){
            $('#errorUrl').show();
            $('#errorLink').hide();
            return false;
        }
        if(link == ""){
            $('#errorLink').show();
            $('#errorUrl').hide();
            return false;
        }
        if(!linkReg.test(link)){
            $('#errorLink').show();
            $('#errorUrl').hide();
            return false;
        }
    });
</script>